package com.ttdevs.ttrss.ui;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ttdevs.ttrss.R;
import com.ttdevs.ttrss.bean.Article;

public class ArticleListAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<Article> mList;

	public ArticleListAdapter(Context context, List<Article> list) {
		mInflater = LayoutInflater.from(context);
		mList = list;
		System.out.println(">>>>>ArticleListAdapter" + mList.toString());
	}

	public void setArticleList(List<Article> list) {
		mList = list;
	}

	@Override
	public int getCount() {
		System.out.println(">>>>>getCount" + mList.toString());
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return mList.get(position).get_id();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.listview_item_article, null);
		}

		Article art = mList.get(position);
		ArticleHolder holder = new ArticleHolder(convertView);
		holder.title.setText(art.getTitle());
		holder.description.setText(art.getDescription());
		holder.pubDate.setText(art.getPubDate());
		holder.link.setText(art.getLink());
		
		return convertView;
	}

	private class ArticleHolder {
		private View mView;
		ImageView head;

		TextView title;
		TextView link;
		TextView icon;
		TextView description;
		TextView author;
		TextView pubDate;
		TextView guid;
		TextView source;
		TextView mark;
		TextView read;
		TextView createTime;
		
		public ArticleHolder(View view){
			mView = view;
			title = (TextView) view.findViewById(R.id.tvTitle);
			description = (TextView) view.findViewById(R.id.tvDescription);
			pubDate = (TextView) view.findViewById(R.id.tvPubDate);
			link = (TextView) view.findViewById(R.id.tvLink);
		}
	}

}
